﻿create PROCEDURE Sync.SP_LoanExecution_SelectChanges
@LastRowVersion rowversion,
@FilterdColumn UNIQUEIDENTIFIER
AS 
BEGIN 
	SELECT 
        t.[LoanExecutionID],
		g.[LoanID],g.[GuarantorName],g.[LoanExecutionStatus],g.[GuarantorSSN],g.[InterestPercentage],g.[LoanPaymentMethodID],g.[LoanAmount],g.[LoanPeriod],g.[TotalLoanAmount],g.[ExecutionDate],g.[CheckNumber],g.[CheckDate],g.[GuarantorAddress],
		t.IsDeleted,
		t.LastUpdatedDate
	FROM [dbo].[LoanExecution] g RIGHT JOIN Sync.LoanExecution_Tracking t  
    ON t.LoanExecutionID = g.LoanExecutionID 
    join CustomerLoans cl
			on g.LoanID = cl.LoanID
	WHERE (@LastRowVersion IS NULL OR t.Version > @LastRowVersion)
		AND ((@FilterdColumn IS NULL) OR (cl.CommitteeID = @FilterdColumn))
    END











